package com.shelpe.services.sinbadgateway.client;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

@FeignClient("algorithmserver")
public interface AlgorithmClient {

	@RequestMapping(method = RequestMethod.GET, value = "/algorithmservice/semiautos/{semiautoId}")
	public SemiautoDto findSemiauto(@PathVariable("semiautoId") Long semiautoId);

	@RequestMapping(method = RequestMethod.GET, value = "/algorithmservice/developments/@stopAll", consumes = "application/json;charset=UTF-8")
	UpdateResponse stopPlans(@RequestParam("container_id") long containerID);

	@RequestMapping(method = RequestMethod.GET, value = "/algorithmservice/developments/@syncLimit", consumes = "application/json;charset=UTF-8")
	UpdateResponse syncPlans(@RequestParam("container_id") long containerID);

	@Data
	@JsonInclude(Include.NON_NULL)
	public static class UpdateResponse {
		private boolean status;
	}

	@Data
	public static class SemiautoDto {
		public final static int DEVICE_ALL = 0;
		public final static int DEVICE_MOBILE = 1;
		public final static int DEVICE_PC = 2;

		@JsonProperty("semiauto_id")
		private long autoID;
		private String title;
		private SemiautoSettings settings;
		private String status;
		private String platform;

		private int device;

		public void fromDevice(int device) {
			if (device == 0) {
				this.device = SemiautoDto.DEVICE_MOBILE;
			} else {
				this.device = SemiautoDto.DEVICE_PC;
			}
		}
	}

	@Data
	public static class SemiautoSettings {
		private int date;
	}
}
